package com.bootdo.appsystem.service.impl;

import com.bootdo.app.utils.redis.AppRedisUtil;
import com.bootdo.app.utils.returnresponse.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.bootdo.appsystem.dao.RegectDao;
import com.bootdo.appsystem.domain.RegectDO;
import com.bootdo.appsystem.service.RegectService;



@Service
public class RegectServiceImpl implements RegectService {
	@Autowired
	private RegectDao regectDao;
	@Autowired
	private RegectService regectService;
	
	@Override
	public RegectDO get(Double regionId){
		return regectDao.get(regionId);
	}

	@Override
	public List<RegectDO> list(Map<String, Object> map){
		return regectDao.list(map);
	}
	
	@Override
	public int count(Map<String, Object> map){
		return regectDao.count(map);
	}
	
	@Override
	public int save(RegectDO regect){
		return regectDao.save(regect);
	}
	
	@Override
	public int update(RegectDO regect){
		return regectDao.update(regect);
	}
	
	@Override
	public int remove(Double regionId){
		return regectDao.remove(regionId);
	}
	
	@Override
	public int batchRemove(Double[] regionIds){
		return regectDao.batchRemove(regionIds);
	}

	@Override
	public ServerResponse<List<RegectDO>> creatCity(Double parantid) {
		List<RegectDO> regectDOList = null;
		try {
			HashMap<String , Object> map = new HashMap<>();
			map.put("parentId" ,parantid );
			regectDOList = AppRedisUtil.get("city" + parantid.intValue());
			if(regectDOList == null){
				regectDOList = regectService.list(map);
				AppRedisUtil.put("city" + parantid.intValue() , regectDOList);
			}
		}catch (RuntimeException e){
			e.printStackTrace();
			return ServerResponse.createByError();
		}
		return ServerResponse.createBySuccess(regectDOList);
	}

}
